Problem
Dynamic len(set(a[L:R]))
Description
In python, we can use len(start(a[L:R])) to calculate the number of distinct values of elements .
Tere are some interactive examples that may help you understand how it is done. Remember that the indices of python lists start from .
1 | >>> |
Your task is to simulate this process.
Input
There will be only one test case. The first line contains two integers and .
The next line contains the original list.
All the integers are between and (inclusive). The next m lines contain the statements
that you need to execute.
A line formatted as ‘ ’ means , and a line formatted as ‘
’ means .
It is guaranteed that the statements will not cause error.
Output
Print the simulated result, one line for each query.
Sample Input
1 | 7 4 |
Sample Output
1 | 3 |
标签:带修莫队
Translation
给出一个长为的序列,有个操作,分为两类:
- 询问此序列位间有多少种不同数
- 将第位改为。
Solution
本题数据范围只有五万,一看就是带根号的算法,可以莫队水过。
我们发现操作是标准莫队,但操作是修改,因而需用带修莫队。
带修莫队即在普通莫队的双指针种再加一个指针,指向时间。对于离线后询问建的扩展,如果是同一时间,就直接移动双指针;如果是不同时间,就先暴力移动时间指针,然后再移双指针即可。
暴力出奇迹~~~
Code
1 |
|